/*
 *  StraightLine.cpp
 *  SoundController0002
 *
 *  Created by jiro on 10/06/28.
 *  Copyright 2010 jiro music. All rights reserved.
 *
 */

#include "StraightLine.h"

namespace sc 
{

	StraightLine::StraightLine( double startX, double startY, double endX, double endY )
		: Line( Line::Type_Straight, startX, startY, endX, endY )
	{
		slope = ( endY - startY ) / ( endX - startX );
		intercept = startY - slope * startX;
	}
	
	StraightLine::~StraightLine()
	{}

	double StraightLine::GetY( double paramX ) const
	{
		return slope * paramX + intercept;
	}

	bool StraightLine::operator < ( const StraightLine& rhs ) const
	{
		bool isEqual;

		isEqual = slope == rhs.slope;
		if ( ! isEqual )
		{
			return slope < rhs.slope;
		}
		
		isEqual = intercept == rhs.intercept;
		if ( ! isEqual )
		{
			return intercept < rhs.intercept;
		}

		return false;		

	}

	bool StraightLine::operator > ( const StraightLine& rhs ) const
	{
		bool isEqual;

		isEqual = slope == rhs.slope;
		if ( ! isEqual )
		{
			return slope > rhs.slope;
		}
		
		isEqual = intercept == rhs.intercept;
		if ( ! isEqual )
		{
			return intercept > rhs.intercept;
		}

		return false;		

	}
	
	bool StraightLine::operator <= ( const StraightLine& rhs ) const
	{
		return ! ( *this > rhs );
	}

	bool StraightLine::operator >= ( const StraightLine& rhs ) const
	{
		return ! ( *this < rhs );
	}

	double StraightLine::GetSlope() const
	{
		return slope;
	}

	double StraightLine::GetIntercept() const
	{
		return intercept;
	}

	std::string StraightLine::ToString() const
	{
		std::stringstream ss;
		ss << Line::ToString() << "\n\t" << "slope: " << slope << ", intercept: " << intercept;
		return ss.str();
	}

}